package cn.johnyu.adapterdemo03;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/21.
 */
public class MyBaseAdapter extends BaseAdapter {

    private List<TfBoy> data;
    private Context context;

    public MyBaseAdapter(Context context,List<TfBoy> data) {
        this.data = data;
        this.context=context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return data.get(position).getId();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater=LayoutInflater.from(context);
        convertView=inflater.inflate(R.layout.tf_layout,null);

        TfBoy b=data.get(position);
        convertView.findViewById(R.id.show).setBackgroundResource(b.getShow());
        ((TextView)convertView.findViewById(R.id.content)).setText(b.getContent());
        ((TextView)convertView.findViewById(R.id.title)).setText(b.getTitle());

        ((TextView)convertView.findViewById(R.id.content)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("john", data.get(position).getContent().toString());
            }
        });

        ((TextView)convertView.findViewById(R.id.title)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("john",data.get(position).getTitle().toString());
            }
        });

        return convertView;
    }
}
